﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Upload images to server using Node JS</title>
    <script src="Scripts/jquery-3.1.1.min.js"></script>
    <script src="Scripts/jquery.form.min.js"></script>
    <script>
        $(document).ready(function () {
            var options = {
                beforeSubmit: showRequest,  // pre-submit 回调
                success: showResponse  // post-submit 回调
            };

            // 绑定到表单的提交事件
            $('#frmUploader').submit(function () {
                $(this).ajaxSubmit(options);
                // 总是返回false以防止标准浏览器提交和页面导航
                return false;
            });
        });

        // pre-submit 回调
        function showRequest(formData, jqForm, options) {
            alert('Uploading is starting.');
            return true;
        }

        // post-submit 回调
        function showResponse(responseText, statusText, xhr, $form) {
            alert('status: ' + statusText + '\n\nresponseText: \n' + responseText );
        }
    </script>
</head>
<body>
    <form id="frmUploader" enctype="multipart/form-data" action="api/Upload/" method="post">
        <input type="file" name="imgUploader" multiple />
        <input type="submit" name="submit" id="btnSubmit" value="Upload" />
    </form>
</body>
</html>